#ifndef _H_INTERPOLATION_CENTER_H_
#define _H_INTERPOLATION_CENTER_H_
/*
History:
	09/12/23 Refactoring
*/
#include <map>
#include "DIVA_KeyFrame.h"
#include "WOPInvokedObj.h"
#include "LyInvokedObj.h"
using namespace std;

typedef map<pair<int,int>,DIVA_KeyFrame*> KeyFrameRecord;//pair<int,int>, first is keyframeNum,second is lineNumber
class InterpolationCenter{
private:
	InterpolationCenter();
	static InterpolationCenter* _myInstance;
	bool _status;//animation功能是否被開啟
	int _frames;//使用者所設定的frame個數 , default為100
	int _speed;//使用者所設定的speed , default為1
	float _frame_time;//timeSinceLastFrame in frameStarted
	//std::pair<int,int> _section;//使用者所設定的重播區間 , 目前沒作用
	int _keyFrameNum;//目前的key frame number
	//int _vmCount;
	KeyFrameRecord _keyframeRecord;// <KeyFrameNumber,LineNumber> <-> DIVA_KeyFrame
	void generateWOPChangeEvents(vector<WOPInvokedObj*>,vector<WOPInvokedObj*>);//generate WOP Change Events
	void generateVMChangeEvents(VMStatusTable,VMStatusTable);//generate VM Change Events
	void generateTargetWOPInterpolation(std::vector<WOPInvokedObj*>);//generate WOP interpolation
	void generateTargetVMInterpolation(DIVA_KeyFrame*);//generate VM interpolation
	void writePastValue(WOPInvokedObj*,WOPInvokedObj*);//for wop to write value
	vector<DIVA_VM*> getNewlyVMs(VMStatusTable,VMStatusTable);//get the newly vms in current key frame
	/*目前DIVA未處理vm刪除的case , 暫時預留method*/
	vector<DIVA_VM*> getDeletionVMs(VMStatusTable,VMStatusTable);
	vector<DIVA_VM*> getLyInvokedVMs(VMStatusTable,VMStatusTable);//get the Ly invoked vms in current key frame
public:
	static InterpolationCenter* getInstance();
	void setStatus(bool status){this->_status = status;}
	void setFrames(int frames){this->_frames = frames;}
	void setSpeed(int speed){this->_speed = speed;}
	//void setSection(pair<int,int> section){this->_section = section;}
	bool getStatus(){return this->_status;}
	int  getFrames(){return this->_frames;}
	int  getSpeed(){return this->_speed;}
	int  getKeyFrameNumber(){return this->_keyFrameNum;}
	//std::pair<int,int> getSection(){return this->_section;}

	void increaseKeyFrameNumber(){
		this->_keyFrameNum++;//increase key frame number;
	}

	void newKeyFrame();//generate a new key frame
	void disableAnimation();//disable animation
	void recoverVM();//when snapShot() is called , we will move VMs back to it's latest position 
	void restartVM();//when animation is enable , it will make VMs to play animation if VMs had events ever. 

	void computeWOPInterpolationBetweenLastTwoKeyFrame();//compute WOP interpolation
	void computeWOPInterpolation(DIVA_KeyFrame*,DIVA_KeyFrame*);//compute WOP interpolation
	void computeVMInterpolationBetweenLastTwoKeyFrame();//compute VM interpolation
	void computeVMInterpolation(DIVA_KeyFrame*,DIVA_KeyFrame*);//compute VM interpolation

	DIVA_KeyFrame* getTargetKeyFrameByKeyFrameNumber(int keyframenum);//get key frame by key frame number
	vector<DIVA_KeyFrame*> getTargetKeyFrameByLineNumber(int lineNumber);//get key frame by line number
	DIVA_KeyFrame* getTheLastKeyFrameInTargetLine(int lineNumber);//get the last key frame by line number
	
	void snapShot();//take a picture for DIVA
	void renderTargetKeyFrame(int);//render key frame
	void render(float);//render method
};
#endif